{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 上周回顾\n",
    "\n",
    "> * 1.list的一般方法/函数的使用案例，如：\\n\",\n",
    ">> 1. append()增加，增加list元素到list的末尾，常见于新建列表\\n\",\n",
    ">> 2. pop(index)/remove(values) 对比两者优势\\n\",\n",
    ">> 3. count()  查看某个元素出现的次数\\n\",\n",
    ">> 4. index() 查看某个元素第一次出现的位置\\n\",\n",
    ">> 5. extend() 两个list合并在一起，也可以用[]+[]来·实现\\n\",\n",
    ">> 6. sort() liat元素的排列\\n\","
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> * 2. list的高级用法：如,\n",
    ">> 1. copy()list (可变的数据类型) 复制 不等价于 赋值，可用[:],\n",
    "来实现,\n",
    ">> 2. enumerate（）枚举，可同时遍历并获取index和values,\n",
    "\n",
    "## 本周内容,\n",
    "\n",
    "### list练习，vowels.py vowels2.py,\n",
    "\n",
    "### list实践 ："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> * vowels2.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "M\n",
      "i\n",
      "i\n",
      "l\n",
      "l\n",
      "i\n",
      "i\n",
      "w\n",
      "a\n",
      "a\n",
      "y\n",
      "s\n"
     ]
    }
   ],
   "source": [
    "vowels  = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "# 检查 word中出现的元音，并打印出来怎么做？\n",
    "# for letter in word:  #  第一个元素letter 请不要和已有的变量重名\n",
    "                       #  第一个元素一般不定义名字，常用item（元素）来命名\n",
    "                       #                            简写 i 来命名\n",
    "                       #  第二个元素word （重要），意味着将遍历的内容\n",
    "                       #  遍历的内容一般是 序列数据 str list\n",
    "for letter in word:\n",
    "    print(letter)\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['i', 'a']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用append () 新建列表\n",
    "found = []\n",
    "for letter in word:\n",
    "#      print(letter)\n",
    "    if letter in vowels: # letter 在 元音字母表中\n",
    "        if letter not in found: # letter 不在found表中\n",
    "            found.append(letter)\n",
    "found"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> * 购物车"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的支付宝余额4000\n",
      "0 ('华为p30', 3800)\n",
      "1 ('mac pro', 16000)\n",
      "2 ('milk tea', 15)\n",
      "3 ('crabs', 88)\n",
      "4 ('Bike', 800)\n",
      "5 ('Watch', 100050)\n",
      "6 ('Head First python', 128)\n",
      "7 ('Book', 100)\n",
      "选择商品的序号:0\n",
      "已添加 华为p30 进你的购物车，您的余额为 200 \n",
      "0 ('华为p30', 3800)\n",
      "1 ('mac pro', 16000)\n",
      "2 ('milk tea', 15)\n",
      "3 ('crabs', 88)\n",
      "4 ('Bike', 800)\n",
      "5 ('Watch', 100050)\n",
      "6 ('Head First python', 128)\n",
      "7 ('Book', 100)\n",
      "选择商品的序号:4\n",
      "你的余额不足，请选择其他的商品或按'q'退出\n",
      "0 ('华为p30', 3800)\n",
      "1 ('mac pro', 16000)\n",
      "2 ('milk tea', 15)\n",
      "3 ('crabs', 88)\n",
      "4 ('Bike', 800)\n",
      "5 ('Watch', 100050)\n",
      "6 ('Head First python', 128)\n",
      "7 ('Book', 100)\n",
      "选择商品的序号:q\n",
      "-----购物清单-----\n",
      "1 ('华为p30', 3800)\n",
      "你的余额还有:200\n"
     ]
    }
   ],
   "source": [
    "product_list=[\n",
    "    ('华为p30',3800),\n",
    "    ('mac pro',16000),\n",
    "    ('milk tea',15),\n",
    "    ('crabs',88),\n",
    "    ('Bike',800),\n",
    "    ('Watch',100050),\n",
    "    ('Head First python',128),\n",
    "    ('Book',100)\n",
    "]\n",
    "shopping_cart=[]\n",
    "\n",
    "Alipay_balance=(input(\"请输入你的支付宝余额\"))\n",
    "if Alipay_balance.isdigit():\n",
    "    Alipay_balance=int(Alipay_balance)\n",
    "    while True:\n",
    "        for item in product_list:\n",
    "            print(product_list.index(item),item)\n",
    "        choice=input(\"选择商品的序号:\")\n",
    "\n",
    "        if choice.isdigit():\n",
    "            choice=int(choice)\n",
    "            if choice >= 0 and choice < 8:\n",
    "                if Alipay_balance >= product_list[choice][1]:\n",
    "                    Alipay_balance = Alipay_balance - product_list[choice][1]\n",
    "                    print(\"已添加 %s 进你的购物车，您的余额为 %s \"%(product_list[choice][0],Alipay_balance))\n",
    "                    shopping_cart.append(product_list[choice])\n",
    "\n",
    "                else:\n",
    "                    print(\"你的余额不足，请选择其他的商品或按'q'退出\")\n",
    "            else:\n",
    "                print(\"商城里没有这个东西，你可以按'q'退出\")\n",
    "        elif choice == \"q\":\n",
    "            print(\"-----购物清单-----\")\n",
    "            for items in shopping_cart:\n",
    "                print(shopping_cart.count(items),items)\n",
    "            print(\"你的余额还有:%s\"%(Alipay_balance))\n",
    "            break\n",
    "        else:\n",
    "            print(\"请输入编号或按‘q’退出\")\n",
    "else:\n",
    "    print(\"请输入正确的余额\")\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
